<template>
  <div>
    <a-card :bordered="false" style="margin-bottom: 10px">
      <!-- 条件搜索 -->
      <div class="table-page-search-wrapper">
        <a-form :labelCol="labelCol" :wrapperCol="wrapperCol" ref="queryForm">
          <a-row :gutter="32">
            <a-col :span="6">
              <a-form-item label="实施时间">
                <a-range-picker
                  style="width: 100%"
                  v-model="dateRange"
                  valueFormat="YYYY-MM-DD"
                  format="YYYY-MM-DD"
                  allow-clear
                  @keyup.enter.native="handleQuery"
                />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="实施人姓名">
                <a-input
                  v-model="queryParam.tz00703"
                  placeholder="请输入实施人姓名"
                  allow-clear
                  @keyup.enter.native="handleQuery"
                />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="被实施人姓名">
                <a-input
                  v-model="queryParam.tz00704"
                  placeholder="请输入被实施人姓名"
                  allow-clear
                  @keyup.enter.native="handleQuery"
                />
              </a-form-item>
            </a-col>

            <a-col>
              <span
                class="table-page-search-submitButtons"
                style="float: right"
              >
                <a-button type="primary" @click="handleQuery"
                  ><a-icon type="search" />查询</a-button
                >
                <a-button style="margin-left: 8px" @click="resetQuery"
                  ><a-icon type="redo" />重置</a-button
                >
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false" class="table-card">
      <!-- 增加 -->
      <import-excel
        title="导入廉政谈话台账"
        :url="importUrl"
        ref="importExcel"
        @ok="getList"
      />
      <biz-taizhang007-add-form
        v-if="showAddModal"
        ref="bizTaizhang007AddForm"
        @ok="getList"
        @close="showAddModal = false"
      />
      <!-- 编辑 -->
      <biz-taizhang007-edit-form
        v-if="showEditModal"
        ref="bizTaizhang007EditForm"
        @ok="getList"
        @close="showEditModal = false"
      />
      <advance-table
        title="廉政谈话台账"
        :pagination="{
          current: queryParam.pageNum,
          pageSize: queryParam.pageSize,
          total: total,
          showSizeChanger: true,
          showLessItems: true,
          showQuickJumper: true,
          showTotal: (total, range) =>
            `第 ${range[0]}-${range[1]} 条，总计 ${total} 条`,
          onChange: changeSize,
          onShowSizeChange: onShowSizeChange,
        }"
        tableKey="base-bizTaizhang007-index-table"
        rowKey="id"
        size="middle"
        @refresh="getList"
        :columns="columns"
        :data-source="bizTaizhang007List"
        :loading="loading"
        :format-conditions="true"
        :row-selection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
        }"
      >
        <div class="table-operations" slot="button">
          <a-button
            type="primary"
            @click="handleAdd"
            v-hasPermi="['biz:bizTaizhang007:add']"
          >
            <a-icon type="plus" />新增
          </a-button>
          <a-button
            type="primary"
            @click="handleImport"
            v-hasPermi="['biz:bizTaizhang007:add']"
          >
            <a-icon type="cloud-upload" />模版导入
          </a-button>
          <a-button
            type=""
            @click="toModel"
            v-hasPermi="['biz:bizTaizhang007:export']"
          >
            <a-icon type="download" />模版下载
          </a-button>
          <a-button
            type="danger"
            v-if="!multiple"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['biz:bizTaizhang007:remove']"
          >
            <a-icon type="delete" />删除
          </a-button>
        </div>

        <span slot="operation" slot-scope="{ text, record }">
          <a
            @click="handleUpdate(record)"
            v-hasPermi="['biz:bizTaizhang007:edit']"
          >
            修改
          </a>
          <a-divider
            type="vertical"
            v-hasPermi="['biz:bizTaizhang007:remove']"
          />
          <a
            @click="handleDelete(record)"
            v-hasPermi="['biz:bizTaizhang007:remove']"
          >
            删除
          </a>
        </span>
        <span slot="rowindex" slot-scope="{ index }">
          {{ index + 1 }}
        </span>
      </advance-table>
    </a-card>
  </div>
</template>
<script>
import {
  listBizTaizhang007,
  delBizTaizhang007,
  exportBizTaizhang007,
} from "@/api/biz/bizTaizhang007";
import AdvanceTable from "@/components/pt/table/AdvanceTable";
import ImportExcel from "../taizhangmodel/modules/importmodel/ImportExcel.vue";
import BizTaizhang007AddForm from "@/views/biz/taizhang007/modules/BizTaizhang007AddForm";
import BizTaizhang007EditForm from "@/views/biz/taizhang007/modules/BizTaizhang007EditForm";
export default {
  name: "BizTaizhang007",
  components: {
    AdvanceTable,
    ImportExcel,
    BizTaizhang007AddForm,
    BizTaizhang007EditForm,
  },
  data() {
    return {
      showAddModal: false,
      showEditModal: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中的主键集合
      selectedRowKeys: [],
      // 选中的数据集合
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      dateRange: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 导入
      importUrl: "/biz/bizTaizhang007/importData",
      // label的百分比
      labelCol: { span: 6 },
      // 内容区域的百分比
      wrapperCol: { span: 18 },
      // 廉政谈话台账表格数据
      bizTaizhang007List: [],
      // 查询参数
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,

        deptId: undefined,

        userName: undefined,

        deptName: undefined,

        tz00701: undefined,

        tz00703: undefined,

        tz00704: undefined,

        tz00705: undefined,
      },
      columns: [
        {
          title: "序号",
          dataIndex: "rowindex",
          ellipsis: true,
          align: "center",
          width: "65px",
          scopedSlots: { customRender: "rowindex" },
        },

        {
          title: "实施时间",
          dataIndex: "tz00701",
          ellipsis: true,
          align: "center",
          width: "165px",
        },
        {
          title: "实施地点",
          dataIndex: "tz00702",
          ellipsis: true,
          align: "center",
          width: "185px",
        },
        {
          title: "实施人姓名",
          dataIndex: "tz00703",
          ellipsis: true,
          align: "center",
          width: "125px",
        },
        {
          title: "被实施人姓名",
          dataIndex: "tz00704",
          ellipsis: true,
          align: "center",
          width: "125px",
        },
        {
          title: "被实施人单位及职务",
          dataIndex: "tz00705",
          ellipsis: true,
          align: "center",
          width: "165px",
        },
        {
          title: "被实施原因",
          dataIndex: "tz00706",
          ellipsis: true,
          align: "center",
        },

        {
          title: "操作",
          dataIndex: "operation",
          align: "center",
          width: "140px",
          scopedSlots: { customRender: "operation" },
        },
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询廉政谈话台账列表 */
    getList() {
      this.loading = true;
      const queryForm = this.addDateRange(this.queryParam, this.dateRange); // 推送时间
      listBizTaizhang007(queryForm).then((response) => {
        this.bizTaizhang007List = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParam.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,

        deptId: undefined,

        userName: undefined,

        deptName: undefined,

        tz00701: undefined,

        tz00703: undefined,

        tz00704: undefined,

        tz00705: undefined,
      };
      this.handleQuery();
    },
    /** 翻页操作 */
    onShowSizeChange(current, pageSize) {
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSizeChange(current, size) {
      this.queryParam.pageNum = 1;
      this.queryParam.pageSize = size;
      this.getList();
    },
    /** 翻页操作 */
    changeSize(current, pageSize) {
      this.queryParam.pageNum = current;
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
      this.ids = this.selectedRows.map((item) => item.id);
      this.single = selectedRowKeys.length !== 1;
      this.multiple = !selectedRowKeys.length;
    },
    /** 查询折叠和展开操作 */
    toggleAdvanced() {
      this.advanced = !this.advanced;
    },
    handleAdd() {
      this.showAddModal = true;
      this.$nextTick(() => this.$refs.bizTaizhang007AddForm.handleAdd());
    },
    handleUpdate(record, ids) {
      this.showEditModal = true;
      this.$nextTick(() =>
        this.$refs.bizTaizhang007EditForm.handleUpdate(record, ids)
      );
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      var that = this;
      const bizTaizhang007Ids = row.id || this.ids;
      this.$confirm({
        title: "确认删除所选中数据?",
        onOk() {
          return delBizTaizhang007(bizTaizhang007Ids).then(() => {
            that.onSelectChange([], []);
            that.getList();
            that.$message.success("删除成功", 3);
          });
        },
        onCancel() {},
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      var that = this;
      this.$confirm({
        title: "是否确认导出?",
        content: "此操作将导出当前条件下所有数据而非选中数据",
        onOk() {
          return exportBizTaizhang007(that.queryParam).then((response) => {
            that.download(response.msg);
            that.$message.success("导出成功", 3);
          });
        },
        onCancel() {},
      });
    },
    // 导入
    handleImport() {
      this.$nextTick(() => this.$refs.importExcel.importExcelHandleOpen());
    },
    toModel() {
      this.$router.push({
        path: "/taizhang/bizTaizhangModel",
      });
    },
  },
};
</script>
